<?php

    define('ABSOLUTE_SERVER_REMOTE_ADDR','http://'.$_SERVER['HTTP_HOST'].'/');
    define('ABSOLUTE_SERVER_DOCUMENT_ROOT','../../../admin/');

    if(file_exists('../../../definitions.inc.php')) include_once('../../../definitions.inc.php');
    include(ABSOLUTE_SERVER_DOCUMENT_ROOT.'session.inc');
    require_once(ABSOLUTE_SERVER_DOCUMENT_ROOT.'funct.inc');   
    
    require_once(ABSOLUTE_SERVER_DOCUMENT_ROOT.'functs.inc');
    require_once('adm_product_link.inc');
    include ABSOLUTE_SERVER_DOCUMENT_ROOT.'color_style.php';

    require_once('../../../classDB.inc.php');
    include '../../'.LANGUAGE;

    if(!GetAdminID($ID)){echo LOGIN_ERR; exit;}
    if(!Right_Check(4)){header('Location:'.ABSOLUTE_SERVER_DOCUMENT_ROOT.'error.php'); exit;}
?>
<html>

<head>
	<?php echo '<meta http-equiv="Content-Type" content="text/html; charset='._CHARSET_.';">'; ?>

	<style  type="text/css"><!--
		table{
            border-bottom-color: black;
            border-top-color: black;
            border-left-color: black;
            border-right-color: black;
            border-collapse: collapse;
            font-size: 10px;
            font-family:  verdana;
        }
        form {margin-top:0pt; margin-bottom:0px;}
        img {margin-top:0pt; margin-bottom:0px;}
        body{
            margin-left:10px;
            margin-right:0pt;
            margin-top:0pt;
            margin-bottom:0pt;
            font-family:  verdana;
            font-size: 10px;
        }
        input {
            border: 1px solid black;
            cursor: pointer;
            background-color: white;
            font-size: 10px;
            margin-left: 0px;
            padding-left: 0px;
            list-style-type: none;
            font-family:  Verdana;
        }
        a {
		  	text-decoration: none; 
		  	font-weight: normal; 
		  	color:black; 
		  	font-size:10px;
		}
		a:hover {
		  	text-decoration: underline; 
			font-weight: normal; 
			color:#808080; 
			font-size:10px;
		}
    --></style>

    <?php
        print "
            <script language=\"JavaScript\">
                <!--
                    function OpenPage(id, count){
                        var ComletPageName= \"".ABSOLUTE_SERVER_DOCUMENT_ROOT."show_product_detail.php\" + \"?ID=\" + id + \"&amp;Count=\" + count;
                        window.close(\"ShopBasketProductDetail\");
                        window.open(ComletPageName,\"ShopBasketProductDetail\",\"width=700px,height=300px,location=no,directories=no,menubar=no,resizeable=yes,status=no,toolbar=no,scrollbars=yes\");
                    }
                //-->
            </script>
        ";
    ?>
	
</head>

<?php
	print "<body bgcolor=\"".BACKGROUND_IN_TABLE."\">";

	$_DB = new classDB();
        if (!$_DB->open()){echo OPEN_DB_ERR; break;}
	
	$Category_ID	= $_REQUEST['ID'];
	$Products_Search= $_REQUEST['Products_Search'];
	
	
do
{
  
	//-----------------------------------------------------------------------------------------------
	//NADPIS
	print "<center><h4 style=\"margin-top:0pt; margin-bottom:0pt;\">".PL_ZOZNAM_PRODUKTOV."</h4></center>";
	//-----------------------------------------------------------------------------------------------
		
	if(($Category_ID=="") and ($Products_Search=="")){mysql_close(); break;}
	
	//-----------------------------------------------------------------------------------------------
	//NADPIS
	print "<center><h5 style=\"margin-top:0pt; margin-bottom:0pt;\">".$_REQUEST['path']."</h5></center>"; 
	//-----------------------------------------------------------------------------------------------
	
	//--------------------------------------------------------------------------------
	//Strankovanie
	if ($Products_Search==""){
        if($Category_ID>0) $sql_psel= "SELECT COUNT(*) FROM products WHERE SC_ID=".$Category_ID;
        else{
          if(trim($Category_ID)!='' and $Category_ID>0) $sql_psel= "SELECT COUNT(*) FROM products WHERE SC_ID=".$Category_ID;
          if(trim($Category_ID)=='-1') $sql_psel= "SELECT COUNT(*) FROM products, product_actions WHERE products.ID=product_actions.PA_ProductID";
          if(trim($Category_ID)=='-2') $sql_psel= "SELECT COUNT(*) FROM products, product_news WHERE products.ID=product_news.PN_ProductID";
          if(trim($Category_ID)=='-3') $sql_psel= "SELECT COUNT(*) FROM products, product_sale  WHERE products.ID=product_sale.PS_ProductID";
        }
    }
	else
		$sql_psel= "SELECT COUNT(*) FROM products 
						WHERE ((Product_Name LIKE '%".$Products_Search."%') OR
                                (Product_Code='".$Products_Search."'))";
	include 'paging.inc';
	$From   = $PageNo*$ItemsOnPage;
    if(trim($From)=='' or !is_numeric($From) or $From<0) $From=0;
	//--------------------------------------------------------------------------------


    print "<br />";

    //**************************************************************************
    //
    //Naplneneie obsahu stranky datami z databazy
    //
    //**************************************************************************

    if ($sql_array_Prodct[0]==0) print "<br><center><b>".PL_ZIADNY_ZAZNAM_NEBOL_NAJDENY."</b></center>";
	
	if ($Products_Search==""){
        if($Category_ID>0)
            $sql_psel=  "
                SELECT * 
                FROM products 
                WHERE SC_ID=".$Category_ID." ORDER BY Product_Name LIMIT ".$From.",".$ItemsOnPage;
        else{
          if(trim($Category_ID)!='' and $Category_ID>0) $sql_psel=  "SELECT * FROM products WHERE SC_ID=".$Category_ID." ORDER BY Product_Name LIMIT ".$From.",".$ItemsOnPage;
          if(trim($Category_ID)=='-1') $sql_psel= "SELECT products.* FROM products, product_actions WHERE products.ID=product_actions.PA_ProductID ORDER BY Product_Name LIMIT ".$From.",".$ItemsOnPage;
          if(trim($Category_ID)=='-2') $sql_psel= "SELECT products.* FROM products, product_news WHERE products.ID=product_news.PN_ProductID ORDER BY Product_Name LIMIT ".$From.",".$ItemsOnPage;
          if(trim($Category_ID)=='-3') $sql_psel= "SELECT products.* FROM products, product_sale WHERE products.ID=product_sale.PS_ProductID ORDER BY Product_Name LIMIT ".$From.",".$ItemsOnPage;
        }
    }
    else
    	$sql_psel= "SELECT * FROM products 
                    WHERE ((Product_Name LIKE '%".$Products_Search."%') OR
                           (Product_Code='".$Products_Search."'))
                    ORDER BY Product_Name LIMIT ".$From.",".$ItemsOnPage;
    $Product_source = mysql_query($sql_psel);
    $counter=0;
    print "<table style=\"border:0px; width:98%;\">";
	while($sql_array_Prodct = mysql_fetch_object($Product_source))
	{
	  	//nastavenie farby riadku
		if(($counter%2))
			$tr_bg_color = TR_BACKGOUND_COLOR_2;
		else
			$tr_bg_color = TR_BACKGOUND_COLOR_1;
	
	    //zobrazenie kodu a nazvu tovaru
	    print "
			<tr style=\"background-color:$tr_bg_color;\">
				<td align=\"left\">
	    			
	    			<b><font color=\"black\"><small>

                        <a
                            href=\"javascript:\"
							target=\"rp_product_detail\"
                            onClick=\"OpenPage(".$sql_array_Prodct->ID.",1);\"
                        >[".PL_KOD.": ".$sql_array_Prodct->Product_Code."]"."</a>

					</small></font color></b>
	    			
	    		</td>
	    		<td align=\"left\" >
	      			<font color=\"".TEXT_COLOR."\"><small>

                        <a
                            href=\"javascript:\"
							target=\"rp_product_detail\"
                            onClick=\"OpenPage(".$sql_array_Prodct->ID.",1);\"
                        >".$sql_array_Prodct->Product_Name."</a>
					  
					</small></font color>
	    		</td>
	        	<td align=\"right\" width=\"122px\">                     
	            	<form action=\"adm_show_selected_products.php\" target=\"selected\" method=\"post\">
	                  <input type=\"hidden\" name=\"Insert_Product_ID\" value=\"".$sql_array_Prodct->ID."\" />
	                  <input type=\"hidden\" value=\"".$_REQUEST['ProductID']."\" name=\"ProductID\" />
	                  <input type=\"submit\" value=\"".PL_PRIDAT_DO_VYBERU."\" style=\"width :120px; background-color: ".BUTTON_ON_OUT.";\"
	                    onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
	                    onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />
					</form>
				</td>				
		";
		$counter++;
	}
	print "</table>";
	
	print "<br />";
	
        
        

	//--------------------------------------------------------------------------------
	//Strankovanie
	if ($Products_Search=="")
		$sql_psel= "SELECT COUNT(*) FROM products WHERE SC_ID=".$Category_ID;
	else
		$sql_psel= "SELECT COUNT(*) FROM products 
						WHERE ((Product_Name LIKE '%".$Products_Search."%') OR
                                (Product_Code='".$Products_Search."'))";
	include 'paging.inc';
	//--------------------------------------------------------------------------------

    mysql_close();
}
while(false)
?>


</body>
</html>